<html>
<head><meta charset="utf-8"><title>Implicit arguments · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html">Implicit arguments</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="187941214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187941214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187941214">(Feb 11 2020 at 18:47)</a>:</h4>
<p>Format strings have a rule that positional arguments (<code>{3}</code>) must appear before named arguments (<code>{foo}</code>) in the argument list of the macro.</p>



<a name="187941346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187941346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187941346">(Feb 11 2020 at 18:49)</a>:</h4>
<p>However in asm it is quite common to have operands that are in a fixed register (e.g. eax) and don't actually appear in the asm string itself. This can happen when performing a syscall or a function call.</p>



<a name="187941358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187941358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187941358">(Feb 11 2020 at 18:49)</a>:</h4>
<p>How should we represent these arguments?</p>



<a name="187941463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187941463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187941463">(Feb 11 2020 at 18:50)</a>:</h4>
<p>Option 1: require implicit argument to be named <code>_</code>: <code>asm!("foo", _ = in("eax") bar)</code></p>



<a name="187941687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187941687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187941687">(Feb 11 2020 at 18:52)</a>:</h4>
<p>Option 2: allow positional arguments to not appear in the template string. We still issue a warning if this is done with a register class rather than a fixed register.</p>



<a name="187942610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187942610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187942610">(Feb 11 2020 at 19:03)</a>:</h4>
<p>I think implicit inputs should simply disallow positional arguments.</p>



<a name="187943490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187943490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187943490">(Feb 11 2020 at 19:13)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> I don't understand, can you explain what you mean by that?</p>



<a name="187943765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187943765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187943765">(Feb 11 2020 at 19:17)</a>:</h4>
<p>If there are any implicit arguments, all other arguments must be named arguments only.</p>



<a name="187944360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187944360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187944360">(Feb 11 2020 at 19:22)</a>:</h4>
<p>But there's nothing explicitly identifying an implicit argument, they look just like a positional argument.</p>



<a name="187944383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187944383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187944383">(Feb 11 2020 at 19:22)</a>:</h4>
<p>(i.e. there's no <code>name = </code> in front of it)</p>



<a name="187949001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187949001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187949001">(Feb 11 2020 at 20:04)</a>:</h4>
<p>I see what you mean now.</p>



<a name="187949142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/187949142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#187949142">(Feb 11 2020 at 20:06)</a>:</h4>
<p>Option 1 seems best then</p>



<a name="188124820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188124820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188124820">(Feb 13 2020 at 16:44)</a>:</h4>
<p>I think it'd be acceptable to allow positional arguments that are explicit registers to not appear in the format string, as long as they're the only positional arguments. Mixing implicit arguments with explicit arguments where both are positional seems problematic and error-prone.</p>



<a name="188126449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188126449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188126449">(Feb 13 2020 at 17:00)</a>:</h4>
<p>In the end I just decided to require all implicit arguments to start with <code>_ = </code></p>



<a name="188126475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188126475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188126475">(Feb 13 2020 at 17:01)</a>:</h4>
<p>It makes the implementation simpler too.</p>



<a name="188143958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188143958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188143958">(Feb 13 2020 at 19:55)</a>:</h4>
<p>That's certainly simpler in implementation, and we can always relax that restriction later.</p>



<a name="188144001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188144001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188144001">(Feb 13 2020 at 19:55)</a>:</h4>
<p>I do suspect it might prove slightly onerous, or perhaps just hard to explain.</p>



<a name="188300428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188300428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188300428">(Feb 15 2020 at 22:00)</a>:</h4>
<p>Actually I've just had an even better idea: we could simply ban any operands with explicit registers from appearing in the template string. So you would have to explicitly write <code>eax</code> in your asm code instead of using placeholders.</p>



<a name="188300450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188300450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188300450">(Feb 15 2020 at 22:01)</a>:</h4>
<p>This leaves only register class operands, which are pretty useless if not used in the template string so we can enforce that.</p>



<a name="188300836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188300836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188300836">(Feb 15 2020 at 22:11)</a>:</h4>
<p>For niche cases like <code>black_box</code>, you can just put the <code>{}</code> in a comment:</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">black_box</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="k">mut</span><span class="w"> </span><span class="n">val</span>: <span class="nc">T</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;# {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">val</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">val</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="188309654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188309654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188309654">(Feb 16 2020 at 02:58)</a>:</h4>
<p>That feels unfortunate. I would rather not repeat a register name.</p>



<a name="188317273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188317273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188317273">(Feb 16 2020 at 08:02)</a>:</h4>
<p>99% of the time if you use an explicit register you're not going to use it in the template string anyways.</p>



<a name="188317289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188317289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188317289">(Feb 16 2020 at 08:02)</a>:</h4>
<p>And even if you do, it's 3 (<code>eax</code>) characters instead of 2 (<code>{}</code>)</p>



<a name="188334314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188334314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188334314">(Feb 16 2020 at 18:28)</a>:</h4>
<p>It's not that it's longer.</p>



<a name="188334325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188334325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188334325">(Feb 16 2020 at 18:28)</a>:</h4>
<p>It's that you have to repeat yourself, rather than naming the register only once.</p>



<a name="188334870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188334870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188334870">(Feb 16 2020 at 18:45)</a>:</h4>
<p>I wouldn't have a problem with prohibiting positional references to explicit registers.</p>



<a name="188334874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Implicit%20arguments/near/188334874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Implicit.20arguments.html#188334874">(Feb 16 2020 at 18:45)</a>:</h4>
<p>But I'd like named references.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>